package gui.naologado;

import gui.ajuda.Ajuda;
import gui.opcoes.Settings;
import java.io.IOException;
import javax.microedition.lcdui.*;
import recados.Recados;

public class LoginMenu extends List implements CommandListener {

    private final Command cmdVoltar;

    public LoginMenu() {
        super("Menu", IMPLICIT);

        try {
            append("Cadastrar-se", Image.createImage("/gui/naologado/cadastra.png"));
            append("Usuarios", Image.createImage("/gui/logado/usuario.png"));
            append("Opções", Image.createImage("/gui/logado/opcoes.png"));
            append("Ajuda", Image.createImage("/gui/logado/ajuda.png"));
        } catch (IOException ex) {
        }

        cmdVoltar = new Command("Voltar", Command.BACK, 0);

        addCommand(cmdVoltar);

        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == List.SELECT_COMMAND) {
            switch (getSelectedIndex()) {
                case 0:
                    Recados.getInstance().setCurrent(Recados.getInstance().getCadastra());
                    break;
                case 1:
                    Recados.getInstance().getUsuarios().setBack(this);
                    Recados.getInstance().setCurrent(Recados.getInstance().getUsuarios());
                    break;
                case 2:
                    Settings set = new Settings(Recados.getInstance());
                    set.setBack(this);
                    Recados.getInstance().setCurrent(set);
                    break;
                case 3:
                    Ajuda a = new Ajuda();
                    Recados.getInstance().setCurrent(a);
                    break;
            }
        } else if (c == cmdVoltar) {
            Recados.getInstance().setCurrent(Recados.getInstance().getLogin());
        }
    }
}
